package cn.mcch.investigator.dialog;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import cn.mcch.investigator.R;
import cn.mcch.investigator.adapter.base.CommonAdapter;
import cn.mcch.investigator.adapter.base.ViewHolder;
import cn.mcch.investigator.application.InvestigatorApplication;
import cn.mcch.investigator.listener.OnCommonClickListener;

/**
 * Created by Administrator on 2016/12/21.
 */
public abstract class BaseListDialog<T> extends BaseDialog {

    private OnCommonClickListener l;

    private List<T> mDatas;

    private String title;

    public BaseListDialog setTitle(String title) {
        this.title = title;
        return this;
    }

    @Override
    protected void initEventListener() {

        setOnItemClickListener(l, R.id.lv_dialog_list);


    }

    @Override
    protected View initView(LayoutInflater inflater, ViewGroup container) {
        return inflater.inflate(R.layout.dialog_list, container, false);
    }

    @Override
    public void initData() {

        setVisibility(R.id.tv_dialog_title, !TextUtils.isEmpty(title)).setText(R.id.tv_dialog_title, title).
                setAdapterViewAdapter(R.id.lv_dialog_list, new CommonAdapter<T>(getDialog().getContext(), R.layout.list_item_dialog_list, mDatas) {
                    @Override
                    protected void convert(ViewHolder viewHolder, T item, int position) {
                        BaseListDialog.this.convert(viewHolder, item, position);
                    }
                });

    }


    public BaseListDialog setOnCommonClickListener(OnCommonClickListener l) {
        this.l = l;
        return this;
    }

    public BaseListDialog setDatas(List<T> mDatas) {
        this.mDatas = mDatas;
        return this;
    }

    public abstract void convert(ViewHolder viewHolder, T item, int position);
}
